function g = graph(map,n,node_info)

g = zeros(n);

for i = 1:n
    
    aux_val = 0;
    
    if (node_info(i,1) > 1)
        for j = node_info(i,3):node_info(i,4)
            if (aux_val(end) ~= map((node_info(i,1) - 1),j) && map((node_info(i,1) - 1),j) ~= 0)
                aux_val = [ aux_val, map((node_info(i,1) - 1),j) ];
            end
        end
    end
        
    if (node_info(i,2) < size(map,1))
        for j = node_info(i,3):node_info(i,4)
            if (aux_val(end) ~= map((node_info(i,2) + 1),j) && map((node_info(i,2) + 1),j)) ~= 0
                aux_val = [ aux_val, map((node_info(i,2) + 1),j) ];
            end
        end
    end
    
    if (node_info(i,3) > 1)
        for j = node_info(i,1):node_info(i,2)
            if (aux_val(end) ~= map(j,(node_info(i,3) - 1)) && map(j,(node_info(i,3) - 1))) ~= 0
                aux_val = [ aux_val, map(j,(node_info(i,3) - 1)) ];
            end
        end
    end
    
    if (node_info(i,4) < size(map,2))
        for j = node_info(i,1):node_info(i,2)
            if (aux_val(end) ~= map(j,(node_info(i,4) + 1)) && map(j,(node_info(i,4) + 1)) ~= 0)
                aux_val = [ aux_val, map(j,(node_info(i,4) + 1)) ];
            end
        end
    end
    
    aux_val(1) = [];
    
    for k = 1:length(aux_val)
        g(i,aux_val(k)) = 1;
    end
    
end

end